import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css'

import Element from 'element-ui'
import moment from 'moment'
// 数据字典
import dict from './components/Dict'
import 'amfe-flexible'
// 权限指令
import checkPer from '@/utils/permission'
import permission from './components/Permission'
import './assets/styles/element-variables.scss'

// 自定义指令
import * as directives from '@/Directives'

for (const k in directives) {
  Vue.directive(k, directives[k])
}

Vue.filter('formatTime', (time) => {
  return moment(Number(time)).format('HH:mm')
})
Vue.filter('formatDate', (time) => {
  return moment(Number(time)).format('YYYY-MM-DD')
})
// global css
import './assets/styles/index.scss'

import App from './App'
import store from './store'
import router from './router/routers'

import './assets/icons' // icon
import './router/index' // permission control

// 引入echarts
import * as echarts from 'echarts'

// 设置全局变量
Vue.prototype.$echarts = echarts

Vue.prototype.navTo = function(url) {
  this.$router.push(url)
}

Vue.prototype.navOpen = function(url) {
  const routeUrl = this.$router.resolve({
    path: url
  })
  window.open(routeUrl.href, '_blank')
}
Vue.prototype.bus = new Vue()

Vue.use(checkPer)
Vue.use(permission)
Vue.use(dict)
Vue.use(Element, {
  size: Cookies.get('size') || 'small' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
